#pragma once

#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstdarg>

// #define DEBUG 0
// #define NORMAL 1
// #define WARNING 2
// #define ERROR 3
// #define FATAL 4

enum level
{
    DEBUG,
    NORMAL,
    WARNING,
    ERROR,
    FATAL
};

const char *galb_level[] = {
    " DEBUG  ",
    " NORMAL ",
    " WARNING",
    " ERROR  ",
    " FATAL  "};

void Messagelog(int level, const char *formart, ...)
{
#ifndef DEBUG_SHOW
    if(level == DEBUG) return;
#endif

    va_list args;
    va_start(args, formart);
    // vprintf(formart, args);

    char logBuffer[1024]; // 基本标准信息
    char stdBuffer[1024]; // 自定义信息内容

    time_t tm = time(nullptr);
    struct tm *local_time = localtime(&tm);

    snprintf(stdBuffer, sizeof stdBuffer, "[%s] [%d年%d月%d日%d:%d:%d] ",
             galb_level[level], local_time->tm_year + 1900, local_time->tm_mon + 1, local_time->tm_mday, local_time->tm_hour, local_time->tm_min, local_time->tm_sec);

    vsnprintf(logBuffer, sizeof logBuffer, formart, args);

    // FILE* fp = fopen("log.txt", "a");
    // fprintf(fp, "%s%s\n", stdBuffer, logBuffer);
    // fclose(fp);
    printf("%s%s\n", stdBuffer, logBuffer);

    va_end(args);
}